<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>SSE Target User Example</title>
    <script>
        let userId = 'user2'; // 目标用户ID

        // 连接到SSE服务器
        const eventSource = new EventSource(`/sse/user/connect?userId=${userId}`);

        // 处理接收到的消息
        eventSource.onmessage = function(event) {
            const newElement = document.createElement("li");
            newElement.textContent = "Received: " + event.data;
            document.getElementById("messages").appendChild(newElement);
        };

        // 处理错误
        eventSource.onerror = function(err) {
            console.error("EventSource failed:", err);
            eventSource.close();
        };
    </script>
</head>
<body>
    <h1>SSE Target User Example</h1>
    <h2>Messages:</h2>
    <ul id="messages"></ul>
</body>
</html>
